//
//  BaseUIViewController.m
//  ShareParking
//
//  Created by STAR on 2017/7/29.
//  Copyright © 2017年 zjw. All rights reserved.
//

#import "BaseUIViewController.h"
#import "AppDelegate.h"

@interface BaseUIViewController ()
@property (weak,nonatomic) UIScrollView *zmScrollView;
@property (nonatomic, strong) NSString *urlStr;
@property (nonatomic, strong) NSDictionary *params;
@end

@implementation BaseUIViewController
- (void)loadView {
    [super loadView];
    [self configNavBackgroundColorUI];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSomeDataSoure];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self configNavBackgroundColorUI];
}

- (void)configNavBackgroundColorUI {
 //   [Utils SetNaviBarGrayStyle:self];
 //   [Utils setNavigationBarLeftButtonWithImage:self imgName:@"back" actionName:@selector(back)];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
}

- (void)configSomeDataSoure {
    self.page = 1;
    self.rows = 10;
    self.maxpage = 1;
    self.dataSoureArray = [[NSMutableArray alloc]init];
    self.recordArray = [[NSMutableArray alloc]init];
}

-(void)addRefreshtoView:(UIScrollView *)scrollView{
    _zmScrollView = scrollView;
//    scrollView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
//    scrollView.mj_footer.automaticallyHidden = YES;
//    scrollView.mj_header = [ZYRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNew)];
//   [self mb_showSVProgress];
    [self addDNZSet];
    //    [scrollView.mj_header beginRefreshing];
}
-(void)addHeaderRefresh:(UIScrollView *)scrollView{
    _zmScrollView = scrollView;
  //  scrollView.mj_header = [ZYRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNew)];
    [self addDNZSet];
}
-(void)addFooterRefresh:(UIScrollView *)scrollView{
    _zmScrollView = scrollView;
   // scrollView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
   // scrollView.mj_footer.automaticallyHidden = YES;
    [self addDNZSet];
}
- (void)addDNZSet {
    _zmScrollView.emptyDataSetSource = self;
    _zmScrollView.emptyDataSetDelegate = self;
}

- (void)endRefresh{
  //  [_zmScrollView.mj_header endRefreshing];
  //  [_zmScrollView.mj_footer endRefreshing];
 //   [self mb_hideSVProgress];
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}
//加载更多
-(void)loadMore {
    if (![self hasMore]) {
   //     [_zmScrollView.mj_footer endRefreshingWithNoMoreData];
        return;
    }
    self.page ++;
    [self loadDataFromService];

}
//加载最新
-(void)loadNew {
    self.page = 1;
 //   [_zmScrollView.mj_footer resetNoMoreData];
    [self loadDataFromService];
}
- (BOOL)hasMore {
    return self.page<self.maxpage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)loadDataFromService {

}

-(NSArray *)dealWithDest:(NSArray *)destArray response:(id)response {
//    BaseModel *model = [[BaseModel alloc]initWithDictionary:response error:nil];
//    self.maxpage = model.maxpage;
//    NSMutableArray *dest = [NSMutableArray arrayWithArray:destArray];
//    if (self.page == 1){
//        [self endRefresh];
//    }else{
//
//    }
//    return dest;
    return nil;
}

-(NSArray *)dealWithDest:(NSArray *)destArray sourceArray:(NSArray *)sourceArray {
    NSMutableArray *dest = [NSMutableArray arrayWithArray:destArray];
    NSMutableArray *source = [NSMutableArray arrayWithArray:sourceArray];
    self.recordArray = source;
    [self endRefresh];
    if (self.page == 1){
        dest = source;
    }else{
        [dest addObjectsFromArray:source];
    }
    return dest;
}



#pragma mark - DZNEmptyDataSetSource,DZNEmptyDataSetDelegate

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    //    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    return  [UIImage imageNamed:@"drink－20"];
    
}


- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    NSString *text =  delegate.hasNetwork ? @"暂无数据..." : @"网络不给力...";
//
//    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16],
//                                 NSForegroundColorAttributeName: [UIColor color_1D1D26]};
//
//    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
    return nil;
}
//无数据时是否可以滚动
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}
@end
